%%% -------------------------------------------------------------------
%%% Author  : gnibre
%%% Description :
%%%
%%% Created : Jul 12, 2009
%%% -------------------------------------------------------------------
-module(ifriend_supervisor).

-behaviour(supervisor).
%% --------------------------------------------------------------------
%% Include files
%% --------------------------------------------------------------------

%% --------------------------------------------------------------------
%% External exports
%% --------------------------------------------------------------------
-export([start/0,start_link/1,start_link/0,start2/0]).

%% --------------------------------------------------------------------
%% Internal exports
%% --------------------------------------------------------------------
-export([
	 init/1
        ]).

%% ====================================================================
%% External functions

start()->
	spawn(fun()->				  
				  supervisor:start_link({local,?MODULE},?MODULE,_Arg = []) 
		  end).

start_link(Args)->	
	supervisor:start_link({local,?MODULE},?MODULE,Args).

start_link()->	
	supervisor:start_link({local,?MODULE},?MODULE,[]).

start2()->	
	{ok,Pid} = supervisor:start_link({local,?MODULE},?MODULE,_Arg = []),
	unlink(Pid).

%% ====================================================================
%% Server functions
%% --------------------------------------------------------------------
%% Func: init/1
%% Returns: {ok,  {SupFlags,  [ChildSpec]}} |
%%          ignore                          |
%%          {error, Reason}
%% --------------------------------------------------------------------

init([]) ->
	
	io:format("init_ in supervisor start!~n"),
	
    AChild = {ifriend_server,
			  {ifriend_server,start,[]},
			  permanent,
			  2000,
			  worker,
			  [o]
			 },
	
    {ok,{
		 {one_for_one,30,1},    %% restart 3 times or more in 10 seconds . stop. 
		 [AChild]}
	}.

%% ====================================================================
%% Internal functions
%% ====================================================================

